var user_index_ops={
    init:function(){
        this.eventBind();
    },

    eventBind:function(){
        $('.like-button').click(function(event){
            var target=$(event.target);
            var current_like=target.attr('like-value');
            var user_id=target.attr('like-user');
            //alert(current_like+'\n'+user_id);

            if(current_like==0)
            {
                $.ajax({
                    url:'/user/'+user_id+'/unfan',
                    method:'POST',
                    dataType:'json',
                    success:function(data){
                        if(data.error !==0)
                        {
                            alert(data.msg);
                            return;
                        }
                        target.attr('like-value',1);
                        target.text('关注');
                    }
                })
            }else{
                $.ajax({
                    url:'/user/'+user_id+'/fan',
                    method:'POST',
                    dataType:'json',
                    success:function(data){
                        if(data.error !==0){
                            alert(data.msg);
                            return;
                        }
                        target.attr('like-value',0);
                        target.text('取消关注');
                    }

                })
            }
        });
    }
};

$(document).ready(function(){
    user_index_ops.init()
});